package com.example.demo.controller;

import com.example.demo.mybatis.entity.User;

import com.example.demo.sever.UserSever;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;



@RestController
@RequestMapping("/learn")
public class userController {

    @Autowired
    private UserSever userSever;

    @PostMapping
    public boolean save(@RequestBody User user) {
        return userSever.insert(user);
    }

    @PutMapping
    public boolean update(@RequestBody User user) {
        return userSever.update(user);
    }

    @DeleteMapping("/{id}")
    public boolean delete(@PathVariable Integer id) {
        return userSever.delectById(id);
    }

    @GetMapping("/{id}")
    public ResponseEntity getById(@PathVariable Integer id) {


        User user = userSever.SelectById(id);
        if (user==null){
         return ResponseEntity.status(500).body("查无此人"+id);
        }
        return ResponseEntity.ok(user);
    }




}
